<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div>
       <canvas id="cvs" width="400" height="400"></canvas>
    </div>
    <script>
        //边框的长度是图形内外各一半，所以应该先填充再画边框
        //线宽是奇数，边缘的颜色值会变浅，线宽是偶数，无影响
       var canvas = document.getElementById('cvs');
       var context = canvas.getContext("2d");
         context.beginPath()
         context.moveTo(200, 200);
         context.lineTo(200, 150);
         context.lineTo(150, 150);
         context.lineTo(150, 200);
         context.closePath();
        
        context.fillStyle="blue"
        context.strokeStyle="red"
        context.lineWidth=7 
         
        context.fill()
         context.stroke()
        
    </script>
</body>
</html>